<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>菜单管理</title>
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/metro/easyui.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/mobile.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/css/common.css"
	rel="stylesheet" />
<style type="text/css">
.row_add {
	color: #2a72c5;
	cursor: pointer;
}

.row_edit {
	color: #2a72c5;
	cursor: pointer;
}

.main {
	margin-right: 15px;
}

ul {
	list-style: none;
}
.icon-list li a{
    cursor:pointer;
}
.main .title{
    border-bottom:1px solid #DDDDDD;
    padding:10px;
}
.main .title span{
    color:#777777;
    font-size:14px;
    font-weight:bold;
}
</style>
</head>
<body>
	<div class="main">
<%--         <!--导航栏-->
        <div class="location">
          <a href="javascript:history.back(-1);" class="back"><i></i><span>返回上一页</span></a>
          <a href="${pageContext.request.contextPath}/bg/home.do" class="home"><i></i><span>首页</span></a>
          <i class="arrow"></i>
          <span>菜单管理</span>
        </div>
        <!--/导航栏--> --%>
		<!--工具栏-->
		<div id="floatHead" class="toolbar-wrap">
			<div class="toolbar">
				<div class="box-wrap">
					<a class="menu-btn"></a>
					<div class="l-list">
						<ul class="icon-list">
							<li><a class="add" onclick="add()"><i></i><span>新增</span></a></li>
							<!-- <li><a id="btnSave" class="save" onclick=""><i></i><span>保存</span></a></li> -->
							<li><a class="all" href="javascript:;" onclick="selectAll()"><i></i><span>全选</span></a></li>
							<li><a id="btnDelete" class="del" onclick="delMenu()"><i></i><span>删除</span></a></li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<!--/工具栏-->

		<table id="treeGrid"></table>
	</div>

	<script src="${pageContext.request.contextPath}/assets/js/jquery-1.11.2.min.js" charset="utf-8"
		type="text/javascript"></script>
	<script	src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/jquery.easyui.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script	src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"
		charset="utf-8" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/assets/js/common.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
	var contextPath = '<%=request.getContextPath()%>';
		$(function() {
			getTreeList();
			$(window).resize(function(){
				//延迟执行,防止多次触发
		        setTimeout(function() {
		        	$('#treeGrid').treegrid('resize');
		        }, 100);
			});
		});
		/*加载菜单列表*/
		function getTreeList(){
		 $('#treeGrid').treegrid({
			    height: 500,
	            title: '菜单管理列表',
	            striped: true,
	            lines: true,
	            animate: true,
	            nowrap: true,
	            collapsible: true,
	            url: contextPath + "/bg/M101.do?rnd="+Math.random(),
	            idField: 'id',
	            treeField: 'name',
	            fitColumns: true,
	            columns: [[{
	                           field: 'id',
	                           title: '选择',
	                           width: 40,
	                           align: 'center',
	                           formatter: function (value, record,index) {
	                           return '<input name="check" value="'+value+'" type="checkbox"/>';
	                           }
	                       },
	                       {
	                           field: 'name',
	                           title: '菜单名称',
	                           width: 200
	                       },
	                       {
	                           field: '_parentId',
	                           title: '父级编码',
	                           width: 200
	                       },
	                       {
	                           field: 'sort',
	                           title: '排序',
	                           width: 100
	                       },
	                       {
	                           field: 'memo',
	                           title: '操作',
	                           width: 100,
	                           align: 'center',
	                           formatter: function (value, record, index) {
	                        	   if(record._parentId!=''){
	                        		   return '<a onclick="add_row('+record.id+')" class="row_add">添加子级</a>&nbsp;<a onclick="edit('+record.id+','+record._parentId+')" class="row_edit">修改</a>';
	                        	   }else{
	                        		   return '<a onclick="add_row('+record.id+')" class="row_add">添加子级</a>&nbsp;<a onclick="edit('+record.id+',-1)" class="row_edit">修改</a>';
	                        	   }	                           
	                           }
	                       }
	            ]]
	        });
		}
		/*新增*/
		function add(){
			location.href=contextPath+"/bg/menu_edit.do?action=add&flag=1&rnd="+Math.random();
		}
		/*添加子级*/
		function add_row(code){
			location.href=contextPath+"/bg/menu_edit.do?action=add&flag=2&code="+code+"&rnd="+Math.random();
		}
		/*编辑*/
		function edit(code,parentCode){
			if(parentCode==-1){
				location.href=contextPath+"/bg/menu_edit.do?action=edit&flag=1&code="+code+"&rnd="+Math.random();			
			}
			else{
				location.href=contextPath+"/bg/menu_edit.do?action=edit&flag=2&code="+code+"&rnd="+Math.random();
			}
		}
		/*删除*/
		function delMenu(){
			var allCheck="";
			$('input[name="check"]:checked').each(function(){
				allCheck+=$(this).val()+",";
			})
			allCheck=allCheck.substring(0,allCheck.length-1);
			$.ajax({
				url : contextPath + "/bg/M104.do",
				data : {"codeList":allCheck,"rnd":Math.random()},
				dataType : 'json',
				success : function(data, textStatus, jqXHR) {
					if(data.status=='true'){
						$.messager.show({title:'提示',msg:'删除成功！',showType:'slide'});
						$('#treeGrid').treegrid('reload');
					}else{
						$.messager.show({title:'提示',msg:'删除失败！',showType:'slide'});
					}
				}
			});
		}
		/*全选*/
		function selectAll(){
			var unCheck=true;
			$('input[name="check"]').each(function(){
				if(!$(this).prop('checked')){
					$(this).prop("checked", true);
					unCheck=false;
				}
			})
			if(unCheck){
				$('input[name="check"]').prop("checked", false);
			}
		}
		
	</script>
</body>
</html>